#include "regx52.h"
#include "STC89C5xRC-rdp.h"
#include "datatype.h"
#include "bit.h"
#include "delay.h"

#include "PWM_Timer2.h"

#define VARIATION 20
#define MAX_BRIGHTNESS 100
#define MIN_BRIGHTNESS 19000

void setup(void)
{
	/* put your setup code here, to run once: */
	time2_init();
	set_duty_ratio_xus(0);
}

void main(void)
{
	uint_16 i = PWM_CYCLE;
	uint_8 mark = FALSE;

	setup();

	while(TRUE) {
		/* put your main code here, to run repeatedly: */
		set_duty_ratio_xus(i);
		
		if (i == MAX_BRIGHTNESS && mark == TRUE)
			mark = FALSE;
		else if (i == MIN_BRIGHTNESS && mark == FALSE)
			mark = TRUE;

		if ( mark == FALSE)
			i += VARIATION;
		else
			i -= VARIATION;
	}
}